<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*|/"><xsl:apply-templates/></xsl:template>

<xsl:template match="text()|@*"><xsl:value-of select="."/></xsl:template>

<xsl:template match='nbsp' name='nbsp'>
<xsl:text disable-output-escaping='yes'>&amp;nbsp;</xsl:text>
</xsl:template>

<xsl:template match="Registration">
  <div class="round_me" style="background:#feeecc; padding:10px;">
    <table border="0" cellspacing="8" cellpadding="0" width="100%">
      <tr>
        <td colspan="4" align="right">
          <xsl:value-of select="format-number(100*(140-@qTotal) div 140,'##')"/>% del test ancora da completare
        </td>
      </tr>
      <form name="formRegistration" method="post" action="{@action}">
        <tr>
          <td colspan="4" align="right">
            <xsl:value-of select="format-number(100-100*(140-@yTotal) div 140,'##')"/>% di purezza raggiunta
          </td>
        </tr>
        <tr>
          <input type="hidden" name="FORM_ID" value="{@ID}"></input>
          <td colspan="4">
          </td>
        </tr>

        <xsl:variable name="nextForm">
          <xsl:for-each select="Question">
            <xsl:choose>
              <xsl:when test='@Type="16"'>
                <xsl:value-of select="@P1"/>
              </xsl:when>
            </xsl:choose>
          </xsl:for-each>
        </xsl:variable>

        <xsl:for-each select="Question">
          <xsl:choose>
            <xsl:when test='@Type="16"'>
              <xsl:variable name="next">
                <xsl:value-of select="@P1"/>
              </xsl:variable>
            </xsl:when>
            <xsl:when test='@Type="15"'>
              <tr>
                <td colspan="4" align="center">
                  <a href="{@P3}">
                    <xsl:value-of select="@Description"/>
                  </a>
                  <br/>
                  <span class="body_10px_red">
                    <xsl:value-of select="@Comment"/>
                  </span>
                </td>
              </tr>
            </xsl:when>
            <xsl:when test='@Type="14"'>
              <tr>
                <td colspan="4" align="center">
                  <input id="SB{@ID}" name="SB{@ID}" onClick="javascript:link('{@P3}');" type="button" value="{@Description}"></input>
                  <br/>
                  <span class="body_10px_red">
                    <xsl:value-of select="@Comment"/>
                  </span>
                </td>
              </tr>
            </xsl:when>
            <xsl:when test='@Type="8"'>
              <tr>
                <td colspan="4" align="center">
                  <input type="hidden" name="qTotal" value="{/Registration/@qTotal}"></input>
                  <input type="hidden" name="yTotal" value="{/Registration/@yTotal}"></input>
                  <input type="hidden" name="nextForm" value="{$nextForm}"></input>
                  <br/>
                  <input type="submit" name="{concat('SUBMIT',@ID)}" value="{@Description}"></input>
                  <br/>
                </td>
              </tr>
            </xsl:when>
            <xsl:when test='@Type="9"'>
              <tr>
                <td colspan="4" align="center">
                  <h4>
                    <xsl:value-of select="@Description"/>
                  </h4>
                </td>
              </tr>
            </xsl:when>
            <xsl:when test='@Type="10"'>
              <tr>
                <td colspan="4" align="left">
                  <b>
                    <xsl:value-of select="@Comment"/>
                  </b>
                </td>
              </tr>
              <tr>
                <td colspan="4" align="left"></td>
              </tr>
            </xsl:when>
            <xsl:otherwise>
              <tr>
                <td>
                  <xsl:value-of select="@Description"/>
                </td>
                <td align="right">
                </td>
                <td>

                </td>
                <td>

                  <xsl:if test='@Type="7"'>
                    <xsl:variable name="TMPID" select="@ID"></xsl:variable>
                    <xsl:for-each select='Answer'>
                      <table cellspacing="0" cellpadding="0">
                        <xsl:if test='@Type="4"'>
                          <tr>
                            <td>
                              <input type="text" name='SE{../@ID}' size="35" maxlength="64"></input>
                            </td>
                          </tr>
                        </xsl:if>
                        <xsl:if test='@Type="1"'>
                          <tr>
                            <td>
                              <select class="body" size="1" name="{concat('SD',@ID)}">
                                <xsl:for-each select="SubAnswer">
                                  <option value="{@ID}">
                                    <xsl:value-of select="."/>
                                  </option>
                                </xsl:for-each>
                              </select>
                            </td>
                          </tr>
                        </xsl:if>
                      </table>
                    </xsl:for-each>
                  </xsl:if>

                  <xsl:if test='@Type="1"'>
                    <select class="body" size="1" name="D{@ID}">
                      <xsl:for-each select="Answer">
                        <option value="{@ID}">
                          <xsl:value-of select="."/>
                        </option>
                      </xsl:for-each>
                    </select>
                  </xsl:if>

                  <xsl:if test='@Type="2"'>
                    <table>
                      <xsl:variable name="radioID" select="concat('R',@ID)"></xsl:variable>

                      <xsl:choose>
                        <xsl:when test='@P1="1"'>
                          <tr>
                            <xsl:for-each select="Answer">
                              <xsl:choose>
                                <xsl:when test='@Selected="1"'>
                                  <td>
                                    <input type="radio" checked="yes" value="{.}" name="{$radioID}"></input>
                                  </td>
                                </xsl:when>
                                <xsl:when test='@Selected="0"'>
                                  <td>
                                    <input type="radio" value="{.}" name="{$radioID}"></input>
                                  </td>
                                </xsl:when>
                              </xsl:choose>
                              <td class="body">
                                <xsl:value-of select="."/>
                              </td>
                            </xsl:for-each>
                          </tr>
                        </xsl:when>
                        <xsl:when test='@P1="2"'>
                          <xsl:for-each select="Answer">
                            <tr>
                              <xsl:choose>
                                <xsl:when test='@Selected="1"'>
                                  <td>
                                    <input type="radio" checked="yes" value="{@ID}" name="{$radioID}"></input>
                                  </td>
                                </xsl:when>
                                <xsl:when test='@Selected="0"'>
                                  <td>
                                    <input type="radio" value="{@ID}" name="{$radioID}"></input>
                                  </td>
                                </xsl:when>
                              </xsl:choose>
                              <td class="body">
                                <xsl:value-of select="."/>
                              </td>
                            </tr>
                          </xsl:for-each>
                        </xsl:when>
                      </xsl:choose>

                    </table>
                  </xsl:if>

                  <xsl:if test='@Type="3"'>
                    <input type="text" id="{concat('gg',@ID)}" name="{concat('gg',@ID)}" class="form" size="2" maxlength="2"></input>
                    /
                    <input type="text" id="{concat('mm',@ID)}" name="{concat('mm',@ID)}" class="form" size="2" maxlength="2"></input>
                    /
                    <input type="text" id="{concat('aaaa',@ID)}" name="{concat('aaaa',@ID)}" class="form" size="4" maxlength="4"></input>
                    <span class="body_10px_red">
                      <xsl:value-of select="@Comment"/>
                    </span>
                  </xsl:if>

                  <xsl:if test='@Type="4"'>
                    <input type="text" id="{concat('E',@ID)}" name="{concat('E',@ID)}" size="35" maxlength="64"></input>
                    <br/>
                    <span class="body_10px_red">
                      <xsl:value-of select="@Comment"/>
                    </span>
                  </xsl:if>

                  <xsl:if test='@Type="5"'>
                    <input type="text" name="{concat('T',@ID)}" size="{@P2}" maxlength="{@P1}"></input>
                    <br/>
                    <span class="body_10px_red">
                      <xsl:value-of select="@Comment"/>
                    </span>
                  </xsl:if>

                  <xsl:if test='@Type="11"'>
                    <input type="text" ID="T{@ID}" name="NICK{@ID}" size="{@P2}" maxlength="{@P1}"></input>
                    <br/>
                    <span class="body_10px_red">
                      <xsl:value-of select="@Comment"/>
                    </span>
                  </xsl:if>

                  <xsl:if test='@Type="12"'>
                    <input type="password" ID="T{@ID}" name="PW{@ID}" size="{@P2}" maxlength="{@P1}"></input>
                    <br/>
                    <span class="body_10px_red">
                      <xsl:value-of select="@Comment"/>
                    </span>
                  </xsl:if>

                  <xsl:if test='@Type="13"'>
                    <TEXTAREA id="TA{@ID}" name="TA{@ID}" rows="{@P1}" cols="{@P2}"></TEXTAREA>
                    <br/>
                    <span class="body_10px_red">
                      <xsl:value-of select="@Comment"/>
                    </span>
                  </xsl:if>

                  <xsl:if test='@Type="6"'>
                    <img src="{@Comment}" border="1"/>
                  </xsl:if>

                </td>
              </tr>
            </xsl:otherwise>
          </xsl:choose>

        </xsl:for-each>


      </form>
    </table>
  </div>
</xsl:template>

</xsl:stylesheet>